<!DOCTYPE html>
<html xmlns:shiro="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<script th:fragment="myCommonJs" th:inline="javascript">
    $(function () {
        $(".prettyTime").each(function () {
            $(this).html(formatter.prettyDate(parseInt($(this).html())));
        });
        $(".prettyPeriod").each(function () {
            $(this).html(formatter.prettyTime(parseInt($(this).html())));
        });

    });

    let formatter = {
        calculateAuditedPeriod: function (start, end) {
            return [[#{message.audit.spend}]] + ': ' + this.prettyTime(end - start) + '<br />(<small> ' + this.formatDateOnly(start) + '--' + this.formatDateOnly(end) + '</small> )';
        }, prettyTime: function (val) {
            if (val / 1000 <= 1) {
                return "1秒"
            } else if (val / 1000 <= 60) {
                return Math.floor((val / 1000)) + "秒"
            } else if (val / 1000 / 60 <= 60) {
                return Math.floor((val / 1000 / 60)) + "分"
            } else if (val / 1000 / 60 / 60 <= 24) {
                return Math.floor((val / 1000 / 60 / 60)) + "小时"
            } else if (val / 1000 / 60 / 60 / 24 <= 1) {
                return "1天"
            } else {
                return Math.floor((val / 1000 / 60 / 60 / 24)) + "天"
            }
        }, formatFileSize: function (val) {
            if (null == val || val == '') {
                return "0 Bytes";
            }
            let unitArr = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
            let index = 0, srcsize = parseFloat(val);
            index = Math.floor(Math.log(srcsize) / Math.log(1024));
            let size = srcsize / Math.pow(1024, index);
            size = size.toFixed(2);
            return size + unitArr[index];
        },formatFileTypeCode: function (val) {
            if (val == 'gdzctzzyzbjhwcqk.xls') {
                return '<i class="fa fa-hand-paper-o"></i>固定资产投资主要指标计划完成情况'
            }
        },
        stateFormatter: function (value, row, index) {
            if (row.status == 1 || row.status == 2)
                return {
                    disabled: true,//设置是否可用
                    checked: false//设置选中
                };
            return value;
        }, formatApproveStatus: function (val) {
            if (val == 1) {
                return '<font color="#1e90ff"><i class="fa fa-thumbs-up"></i>' + [[#{message.audit.agree}]] + '</font>'
            } else if (val == 99) {
                return '<font color="red"><i class="fa fa-thumbs-down"></i>' + [[#{message.audit.disagree}]] + '</font>'
            }else if (val == 88) {
                return '<font color="#1e90ff"><i class="fa fa-thumbs-up"></i>通过结束</font>'
            }
            return val;
        }, formatEquipmentStatus: function (value) {
            if (value == '1') {
                return '在用'
            } else if (value == '2') {
                return '在修'
            } else if (value == '3') {
                return '待修'
            } else if (value == '4') {
                return '备用'
            } else if (value == '5') {
                return '淘汰在用'
            } else if (value == '6') {
                return '待废在用'
            } else if (value == '7') {
                return '待报废'
            } else if (value == '8') {
                return '已报废'
            } else if (value == '9') {
                return '租出'
            } else if (value == '10') {
                return '备租'
            } else if (value == '11') {
                return '救援设备'
            } else if (value == '12') {
                return '长期储备'
            } else if (value == '13') {
                return '闲置'
            }
        },
        formatProcessType: function (val) {
            if (val == 'equipmentDoc') {
                return '<i class="fa fa-hand-paper-o"></i>设备档案'
            } else if (val == 'leasingPlanning') {
                return '<i class="fa fa-files-o "></i>租赁计划'
            } else if (val == 'leasingApplication') {
                return '<i class="fa fa-files-o "></i>租赁合同'
            } else if (val == 'throwLeasingApplication') {
                return '<i class="fa fa-user-secret"></i>退租申请'
            } else if (val == 'outStorage') {
                return '<i class="fa fa-warning"></i>出库'
            } else if (val == 'inStorage') {
                return '<i class="fa fa-edit"></i>入库'
            } else if (val == 'receive') {
                return '<i class="fa fa-edit"></i>领用'
            } else if (val == 'rollback') {
                return '<i class="fa fa-edit"></i>退回'
            } else if (val == 'handOver') {
                return '<i class="fa fa-edit"></i>移交'
            } else if (val == 'scrap') {
                return '<i class="fa fa-edit"></i>报废'
            } else if (val == 'maintain') {
                return '<i class="fa fa-edit"></i>维修'
            } else if (val == 'other') {
                return '<i class="fa fa-edit"></i>位置状态变动'
            }
        },
        formatDateOnly: function (val) {
            if (val != null) {
                let oDate = new Date(val),
                    oYear = oDate.getFullYear(),
                    oMonth = oDate.getMonth() + 1,
                    oDay = oDate.getDate(),
                    oHour = oDate.getHours(),
                    oMin = oDate.getMinutes(),
                    oSen = oDate.getSeconds(),
                    oTime = oYear + '-' + this.getzf(oMonth) + '-' + this.getzf(oDay) + ' ' + this.getzf(oHour) + ':' + this.getzf(oMin) + ':' + this.getzf(oSen);//最后拼接时间
                return oTime;
            }
        }, getzf: function (num) {
            if (parseInt(num) < 10) {
                num = '0' + num;
            }
            return num;
        },
        formatDate: function (val) {
            return this.prettyDate(val) + '<br/><font size="1"><i>' + this.formatDateOnly(val) + '</i></font>';
        }, prettyDate: function (val) {
            let currentDate = new Date();
            let oDate = new Date(val);
            let lag = currentDate.getTime() - val;
            let lagd = lag / 1000 / 60 / 60 / 24;
            if (lagd < 2) {
                if (currentDate.getDate() == oDate.getDate()) {
                    return [[#{message.tip.today}]]
                } else if (currentDate.getDate() - oDate.getDate() == 1) {
                    return [[#{message.tip.yesterday}]]
                } else if (currentDate.getDate() - oDate.getDate() == 2) {
                    return [[#{message.tip.yesterday.before}]]
                } else {
                    return [[#{message.tip.yesterday}]]
                }
            }
            if (lagd < 31) {
                return parseInt(lagd) + ' ' + [[#{message.tip.dayAgo}]]
            }
            if (lagd >= 365 && currentDate.getFullYear() > oDate.getFullYear()) {
                return Math.ceil(currentDate.getFullYear() - oDate.getFullYear()) + ' ' + [[#{message.tip.yearAgo}]]
            }
            if (lagd >= 31) {
                return parseInt(lagd / 30) + ' ' + [[#{message.tip.monthAgo}]]
            }
            if (currentDate.getFullYear() > oDate.getFullYear()) {
                return parseInt(lagd / 30) + ' ' + [[#{message.tip.monthAgo}]]
            }
            return val;
        }, formatAuditStatus: function (val) {
            if (val == 0) {
                return '<font color="#d3d3d3"><i class="fa fa-warning"></i>' + [[#{message.audit.status.pending}]] + '</font>'
            } else if (val == 1) {
                return '<font color="#556b2f"><i class="fa fa-hand-o-right"></i>' + [[#{message.audit.status.auditing}]] + '</font>'
            } else if (val == 2) {
                return '<font color="#1e90ff"><i class="fa fa-thumbs-up"></i>' + [[#{message.audit.status.audited}]] + '</font>'
            } else if (val == 3) {
                return '<font color="red"><i class="fa fa-times"></i>' + [[#{message.audit.status.rejected}]] + '</font>'
            }
            return val;
        }, formatMaintainType: function (val) {
            if (val == 1) {
                return '<font color="#556b2f"><i class="fa  fa-wrench"></i>大修</font>'
            } else if (val == 2) {
                return '<font color="#1e90ff"><i class="fa  fa-wrench"></i>中修</font>'
            } else if (val == 3) {
                return '<font color="red"><i class="fa  fa-wrench"></i>小修</font>'
            }
            return val;
        }
    };

    let commonAction = {
        delAction: function (id, url, redirect, pop) {
            $('#' + pop).modal("show");
            $("#confirmDelete").click(function () {
                $.ajax({
                    url: url,
                    data: 'uuid=' + id,
                    type: "post",
                    success: function (data) {
                        if (!redirect) {
                            return;
                        }
                        if (typeof redirect == 'function') {
                            redirect();
                        } else {
                            location.href = redirect
                        }
                    }
                });
                $('#' + pop).modal("hide");
            });
        }
    };

    let commonNoAction = {
        delNoAction: function (id, url, redirect, pop) {
            $('#' + pop).modal("show");
            $("#confirmDelete").click(function () {
                $.ajax({
                    url: url,
                    data: 'id=' + id,
                    type: "post",
                    success: function (data) {
                        if (!redirect) {
                            return;
                        }
                        if (typeof redirect == 'function') {
                            redirect();
                        } else {
                            location.href = redirect
                        }
                    }
                });
                $('#' + pop).modal("hide");
            });
        }
    };
    /**
     * 发送AJAX请求
     * doService.doService("/contract/queryMaxNo", "year",2019, "month",12,...)
     * Add Hjs
     */
    let doService = {
        do: function () {
            //参数处理
            if (arguments.length % 2 == 0) {
                //alert('参数错误!');
                return;
            }
            //拼接参数
            let urlParams = '';
            for (let i = 1; i < arguments.length; i = i + 2) {
                if (urlParams != '') {
                    urlParams += "&";
                }
                urlParams += arguments[i] + "=" + arguments[i + 1];
            }
            let dat = '';
            $.ajax({
                url: arguments[0],
                data: urlParams,
                type: "post",
                dataType: "json",
                async: false,
                success: function (data) {
                    dat = data;
                }
            });
            return dat;
        }
    };


    function resetTable() {
        $('.search').val("");
        createTable()
    }

    function refreshQuery() {
        $("#query-search-div :input").val('');
    }


    function reject() {
        let url = [[@{'/process/reject'}]];
        let taskId = $('#taskId').val();
        let processInstanceId = $('#processInstanceId').val();
        let type = $('#type').val();
        let uuid = $('#uuid').val();
        let remark = $('#remark').val();
        $.ajax({
            url: url,
            data: 'uuid=' + uuid + '&type=' + type + '&processInstanceId=' + processInstanceId + '&taskId=' + taskId + '&remark=' + remark,
            type: "post",
            success: function (data) {
                if (data == 'ok') {
                    location.href = [[@{'/process/gopending'}]]
                }
            }
        });
    }

    function passall() {
        let url = [[@{'/process/passall'}]];
        let taskId = $('#taskId').val();
        let processInstanceId = $('#processInstanceId').val();
        let type = $('#type').val();
        let uuid = $('#uuid').val();
        let remark = $('#remark').val();
        $.ajax({
            url: url,
            data: 'uuid=' + uuid + '&type=' + type + '&processInstanceId=' + processInstanceId + '&taskId=' + taskId + '&remark=' + remark,
            type: "post",
            success: function (data) {
                if (data == 'ok') {
                    location.href = [[@{'/process/gopending'}]]
                }
            }
        });
    }

    function resolveAuditStatus(obj) {
        if (obj != '' || obj != null || obj != undefined) {
            let ret = formatter.formatAuditStatus(obj);
            $('#auditStatus').html(ret)
        }
    }

    function resolveMaintainType(obj) {
        if (obj != '' || obj != null || obj != undefined) {
            let ret = formatter.formatMaintainType(obj);
            $('#maintainTypeName').html(ret)
        }
    }


    function userAuthorization(val) {
        let arr = [];
        //console.log(val);
        //console.log(val.sysUserRoles);
        val.sysUserRoles.forEach(function (element) {
            element.sysRole.powers.forEach(function (element2) {
                arr.push(element2.power)
            });
        });
        localStorage.setItem("userAuthorization", arr);
    }

    function checkAuthorization(val) {
        let user = localStorage.getItem("userAuthorization");
        let arr = user.split(",");
        return arr.indexOf(val) >= 0;
    }

    let myFileAction = {
        do: function (inputElement, idField, type, ret) {
            let uploadUrl = [[@{'/file/upload'}]];
            let deleteUrl = [[@{'/file/delete'}]];
            let arrId = [];
            $("#" + inputElement).uploadFile({
                url: uploadUrl + "?type=" + type,                 //文件上传url
                returnType: 'json',              //服务返回数据
                showDone: true,                     //是否显示"Done"(完成)按钮
                showDelete: true,                  //是否显示"Delete"(删除)按钮
                onLoad: function (obj) {
                    if (ret) {
                        for (let a = 0, lengths = ret.length; a < lengths; a++) {
                            obj.createProgress(ret[a].fileName, ret[a].filePath, ret[a].fileSize, ret[a].uuid);
                            arrId.push(ret[a].uuid);
                        }
                        $('#' + idField).val(arrId);
                    }
                },
                deleteCallback: function (data, pd) {
                    $.ajax({
                        type: "post",
                        url: deleteUrl + "?uuid=" + data,
                        success: function (datas) {
                            let index = arrId.indexOf(data);
                            if (index > -1) {
                                arrId.splice(index, 1);
                            }
                        }
                    });
                },
                onSuccess: function (files, data, xhr, pd) {
                    arrId.push(data);
                    $('#' + idField).val(arrId);
                }
            });
        }
    };
</script>


</html>

